package com.ruoyi.business.service.impl;

import java.util.List;

import com.ruoyi.business.domain.enums.GradeLevelEnum;
import com.ruoyi.business.domain.enums.HeightWeightGradeEnum;
import com.ruoyi.business.domain.enums.ProjectTypeEnum;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ScoringStandardMapper;
import com.ruoyi.business.domain.ScoringStandard;
import com.ruoyi.business.service.IScoringStandardService;
import org.springframework.util.ObjectUtils;

/**
 * 评分标准Service业务层处理
 * 
 * @author lcz
 * @date 2025-03-31
 */
@Service
public class ScoringStandardServiceImpl implements IScoringStandardService 
{
    @Autowired
    private ScoringStandardMapper scoringStandardMapper;

    /**
     * 查询评分标准
     * 
     * @param id 评分标准主键
     * @return 评分标准
     */
    @Override
    public ScoringStandard selectScoringStandardById(Long id)
    {
        return scoringStandardMapper.selectScoringStandardById(id);
    }

    /**
     * 查询评分标准列表
     * 
     * @param scoringStandard 评分标准
     * @return 评分标准
     */
    @Override
    public List<ScoringStandard> selectScoringStandardList(ScoringStandard scoringStandard)
    {
        return scoringStandardMapper.selectScoringStandardList(scoringStandard);
    }

    /**
     * 导出列表
     *
     * @param scoringStandard 评分标准
     * @return 评分标准
     */
    @Override
    public List<ScoringStandard> exportList(ScoringStandard scoringStandard)
    {
        return scoringStandardMapper.exportList(scoringStandard);
    }

    /**
     * 新增评分标准
     * 
     * @param scoringStandard 评分标准
     * @return 结果
     */
    @Override
    public int insertScoringStandard(ScoringStandard scoringStandard)
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (!ObjectUtils.isEmpty(sysUser.getSchoolId())){
            scoringStandard.setSchoolId(sysUser.getSchoolId());
        }
        if (scoringStandard.getProjectId().equals(ProjectTypeEnum.HEIGHT.getCode())){
            scoringStandard.setLevelName(HeightWeightGradeEnum.getGrade(scoringStandard.getLevelId().toString()).getValue());
        }else {
            scoringStandard.setLevelName(GradeLevelEnum.getGrade(scoringStandard.getLevelId().toString()).getValue());
        }
        scoringStandard.setCreateTime(DateUtils.getNowDate());
        return scoringStandardMapper.insertScoringStandard(scoringStandard);
    }

    /**
     * 修改评分标准
     * 
     * @param scoringStandard 评分标准
     * @return 结果
     */
    @Override
    public int updateScoringStandard(ScoringStandard scoringStandard)
    {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        if (!ObjectUtils.isEmpty(sysUser.getSchoolId())){
            scoringStandard.setSchoolId(sysUser.getSchoolId());
        }
        scoringStandard.setUpdateTime(DateUtils.getNowDate());
        return scoringStandardMapper.updateScoringStandard(scoringStandard);
    }

    /**
     * 批量删除评分标准
     * 
     * @param ids 需要删除的评分标准主键
     * @return 结果
     */
    @Override
    public int deleteScoringStandardByIds(Long[] ids)
    {
        return scoringStandardMapper.deleteScoringStandardByIds(ids);
    }

    /**
     * 删除评分标准信息
     * 
     * @param id 评分标准主键
     * @return 结果
     */
    @Override
    public int deleteScoringStandardById(Long id)
    {
        return scoringStandardMapper.deleteScoringStandardById(id);
    }
}
